<?php

//折翼天使资源社区 提供 www.zheyitianshi.com
if (!defined('IN_IA')) {
	die('Access Denied');
}
global $_W, $_GPC;
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
$openid = m('user')->getOpenid();
$uniacid=$_W['uniacid'];
$recordid = intval($_GPC['recordid']);
if($operation=="display"){
if(!empty($_GPC['data'])){
    $ordersn = m('common')->createNO('commission_apply_order', 'ordersn', 'XD');
    $data=$_GPC['data'];
    $data['uniacid']=$_W['uniacid'];
    $data['openid']=$openid;
    if($_GPC['data']['type']==1){
    $data['price']=980;     
    }
    if($_GPC['data']['type']==2){
    $data['price']=2980;  
    }
    if($_GPC['data']['type']==3){
    $data['price']=4980;  
    }
    $data['createtime']=time();
    $data['ordersn']=$ordersn;
    $record1=pdo_fetch('select * from '.tablename('ewei_shop_commission_apply_order').' where uniacid=:uniacid and type=:type and openid=:openid and status=1 order by id desc ',array(':uniacid'=>$_W['uniacid'],':type'=>$_GPC['data']['type'],':openid'=>$openid));
    $record2=pdo_fetch('select * from '.tablename('ewei_shop_commission_apply_order').' where uniacid=:uniacid and type=:type and openid=:openid and status=2 order by id desc ',array(':uniacid'=>$_W['uniacid'],':type'=>$_GPC['data']['type'],':openid'=>$openid));
    if($record1){
      show_json(-1, '您已购买该类型的店铺，无需重复购买!');  
    }
    if($record2){
      show_json(-1, '您已开通该类型的店铺，无需重复开通!');  
    }
    if(empty($record1) && empty($record2)){
    pdo_insert('ewei_shop_commission_apply_order', $data);
    $recordid = pdo_insertid();
     show_json(1,array('recordid'=>$recordid));
    die;
    }
}
include $this->template('shop/apply');
exit;
}